﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyFrameWork.Dam;
using System.Data;
using MvcApplication5.DAM;
using MvcApplication5.Models;
using System.Reflection;
using MyFrameWork.Common;

namespace MvcApplication5.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/
        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Login()
        {
            Session["LoginUser"] = "";
            return View();
        }
        /// <summary>
        /// 注册页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Register()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 会员登录
        /// </summary>
        /// <param name="model">会员信息</param>
        /// <returns>查询结果</returns>
        [HttpPost]
        public ActionResult LoginClick()
        {
            try
            {
                UserModel userModel = JsonUtility.Parse<UserModel>(CommonUtility.GetAjaxDataString());


                AjaxResultModel resultModel = new AjaxResultModel();
                AdminDAM adminDAM = new AdminDAM();
                DataSet ds = adminDAM.SelectData(userModel);

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    List<UserModelExt> userList = DataConvert<UserModelExt>.ConvertModelToDataSet(ds);
                    Session["LoginUser"] = userList[0];
                    resultModel.result = 1;
                    resultModel.message = "success";

                }
                else
                {
                    resultModel.result = -1;
                    resultModel.message = "fail";
                }

                return Content(JsonUtility.ToJSON(resultModel));
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
